#include "testApp.h"
#include "kitButton.h"

/**
 VERSION 0.01
 April 13th 2010
 
 TODO
 - event based
 - fullscreen: reposition elements
 - loading sounds from xml file
 - make pad arrays to for-loop update() and draw()
 **/

//--------------------------------------------------------------
void testApp::setup(){
	//of
	ofSetWindowTitle("xboxControllers");
	ofSetFrameRate(40); 
	ofSetVerticalSync(true);
	ofBackground(0, 0, 0);
	ofEnableAlphaBlending();
	
	//font
	font.loadFont("fonts/KabelLTStd-Book.otf", 32, true, true, false);
	sprintf(eventString, "no drum hit yet");
	
	//drum buttons
	uint xCentre = ofGetWidth()/2;
	uint offset = 100;
	padRed.setup(255, 0, 0, 80, 360, xCentre-offset*3, 300);
	padYellow.setup(255, 255, 0, 80, 360, xCentre-offset, 200);
	padBlue.setup(0, 0, 255, 80, 360, xCentre+offset, 200);
	padGreen.setup(0, 124, 0, 80, 360, xCentre+offset*3, 300);
	kickBlack.setup(255, 150, 0, 80, 6, xCentre, 600);
	
	//sounds
	kick.loadSound("sounds/kick.wav");
	snare.loadSound("sounds/snare.wav");
	hihatClosed.loadSound("sounds/hat.wav");
	hihatOpen.loadSound("sounds/tom.wav");
	cymbal.loadSound("sounds/crash.wav");
	
	//setMultiPlay true
	kick.setMultiPlay(true);
	snare.setMultiPlay(true);
	hihatClosed.setMultiPlay(true);
	hihatOpen.setMultiPlay(true);
	cymbal.setMultiPlay(true);
	
	//volume control
	hihatClosed.setVolume(0.2);
	cymbal.setVolume(0.3);
	
	//bool for keys
	bReleasedKick = true;	//kick is the only button on the drumkit that can be 'hold'
}

//--------------------------------------------------------------
void testApp::update(){
	padRed.update();
	padYellow.update();
	padBlue.update();
	padGreen.update();
	kickBlack.update();
}

//--------------------------------------------------------------
void testApp::draw(){
	ofSetColor(0xffffff);
	font.drawString(eventString, 100, 60);
	
	padRed.draw();
	padYellow.draw();
	padBlue.draw();
	padGreen.draw();
	kickBlack.draw();
}

//--------------------------------------------------------------
void testApp::keyPressed  (int key){
	switch(key) {
		case 'f':
			ofToggleFullscreen();
			break;
		case 'l':
			snare.play();
			padRed.toggleActive();			
			break;
		case 'u':
			hihatClosed.play();
			padYellow.toggleActive();
			break;
		case 'm':
			hihatOpen.play();
			padBlue.toggleActive();
			break;
		case 'o':
			cymbal.play();
			padGreen.toggleActive();
			break;
		case 'k':
			if(bReleasedKick) {
				kick.play();
				kickBlack.toggleActive();
				bReleasedKick = false;
			} 
			break;
		default:
			break;
	}
	sprintf(eventString, "drum keyPressed = (%c)", key);
}

//--------------------------------------------------------------
void testApp::keyReleased  (int key){
	switch(key) {
		case 'k':
			bReleasedKick = true;
			break;
		default:
			break;
	}

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}


//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}
